/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CA;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

/**
*
* @author diego
*/
public class DBEngine
{
/**
* Connect to database
* @return Connection to database
* @throws java.lang.Exception
*/
public Connection dbConnection()throws Exception
{
Class.forName("org.sqlite.JDBC");
String myDB ="jdbc:sqlite:ca/db.sqlite";
return DriverManager.getConnection(myDB,"","");
}

/**
* This method will load vector of vector of string and load all the data in
* the vector
* @return vector of vector of string
* @throws java.lang.Exception
*/
public Vector getRichieste()throws Exception
{
Vector<Vector<String>> richieste = new Vector<Vector<String>>();

Connection conn = dbConnection();
PreparedStatement pre = conn.prepareStatement("select * from richiesta");

ResultSet rs = pre.executeQuery();

while(rs.next())
{
Vector<String> richiesta = new Vector<String>();
richiesta.add(rs.getString(1)); 
richiesta.add(rs.getString(2)); 
richiesta.add(rs.getString(4));
richiesta.add(rs.getString(3)); 
richieste.add(richiesta);
}

/*Close the connection after use (MUST)*/
if(conn!=null)
conn.close();

return richieste;
}
}